package com.kaiwukj.android.ufamily.mvp.ui.page.order.detail;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alipay.sdk.app.PayTask;
import com.blankj.utilcode.constant.TimeConstants;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.hyphenate.chat.EMClient;
import com.hyphenate.easeui.EaseConstant;
import com.kaiwukj.android.mcas.di.component.AppComponent;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.review.BaseMvpActivity;
import com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt;
import com.kaiwukj.android.ufamily.app.constant.Constant;
import com.kaiwukj.android.ufamily.di.component.DaggerOrderComponent;
import com.kaiwukj.android.ufamily.di.module.OrderModule;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.OrderEvent;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.PayEvent;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.PayInfo;
import com.kaiwukj.android.ufamily.mvp.http.entity.event.PayResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.OrderPayParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.HouseKeeperResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.OrderDetailResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.OrderResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ServiceResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.resultbak.AlipayResult;
import com.kaiwukj.android.ufamily.mvp.ui.page.home.message.ChatActivity;
import com.kaiwukj.android.ufamily.mvp.ui.page.order.OrderContract;
import com.kaiwukj.android.ufamily.mvp.ui.page.order.OrderPresenter;
import com.kaiwukj.android.ufamily.mvp.ui.page.service.order.OrderResultActivity;
import com.kaiwukj.android.ufamily.utils.FormatUtils;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
import com.qmuiteam.qmui.widget.popup.QMUIPopup;
import com.qmuiteam.qmui.widget.popup.QMUIPopups;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

@Route(path = ARouterUrlKt.OrderDetailUrl)
public class OrderDetailActivity extends BaseMvpActivity<OrderPresenter> implements OrderContract.View {

    private static final int REQUEST_REFUND = 101;
    private static final int REQUEST_EVALUATE = 102;

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_event_time_flag)
    TextView tvEventTimeFlag;
    @BindView(R.id.tv_event_time)
    TextView tvEventTime;
    @BindView(R.id.iv_status)
    ImageView ivStatus;
    @BindView(R.id.tv_refunds_msg)
    TextView tvRefundsMsg;
    @BindView(R.id.tv_address_name)
    TextView tvAddressName;//收货人姓名
    @BindView(R.id.tv_address_phone)
    TextView tvAddressPhone;//收货联系方式
    @BindView(R.id.tv_address)
    TextView tvAddress;//收货地址
    @BindView(R.id.tv_appointment_time)
    TextView tvAppointmentTime;
    @BindView(R.id.tv_service_manager)
    TextView tvServiceManager;
    @BindView(R.id.tv_service_type)
    TextView tvServiceParamsName;
    @BindView(R.id.tv_service_price)
    TextView tvServiceParamsPrice;
    @BindView(R.id.tv_service_count)
    TextView tvServiceCount;
    @BindView(R.id.container_fee)
    ViewGroup containerFee;
    @BindView(R.id.tv_fee_total)
    TextView tvFeeTotal;
    @BindView(R.id.tv_fee_discount)
    TextView tvFeeDiscount;
    @BindView(R.id.tv_pay_fee_total)
    TextView tvPayFeeTotal;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;
    @BindView(R.id.tv_order_pay_time)
    TextView tvOrderPayTime;
    @BindView(R.id.tv_order_pay_way)
    TextView tvOrderPayWay;
    @BindView(R.id.tv_order_remark)
    TextView tvOrderRemark;

    @BindView(R.id.tv_action_more)
    View viewActionMore;
    @BindView(R.id.btn_01)
    QMUIRoundButton btn01;
    @BindView(R.id.btn_02)
    QMUIRoundButton btn02;
    @BindView(R.id.btn_03)
    QMUIRoundButton btn03;

    private QMUIPopup deletePopup;


    private OrderDetailResult orderDetailResult;

    @Autowired
    int orderId;

    private int payWay = 0;


    @OnClick(R.id.container_left)
    void onBackClick() {
        onBackPressedSupport();
    }


    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        super.setupActivityComponent(appComponent);
        DaggerOrderComponent.builder()
                .appComponent(appComponent)
                .orderModule(new OrderModule(this))
                .build().inject(this);
    }

    @Override
    protected int getLayoutId() {
        ARouter.getInstance().inject(this);
        QMUIStatusBarHelper.translucent(this);
        return R.layout.activity_order_detail;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        if (orderId <= 0) {
            showMessage("订单异常");
            return;
        }
        showLoading();
        loadData();
    }

    private void loadData() {
        mPresenter.getOrderById(orderId);
    }

    @Override
    public void onFetchOrder(List<OrderResult> results) {

    }

    @Override
    public void onGetOrder(OrderDetailResult result) {
        orderDetailResult = result;
        displayOrder(result);
        hideLoading();
    }

    @Override
    public void onOrderPayResult(Map<String, Object> result) {
        hideLoading();
        if (payWay == 1) {
            payByAlipay(GsonUtils.toJson(result));
        } else {
            payByWechat(GsonUtils.toJson(result));
        }
    }

    @Override
    public void onGetHouseKeeper(HouseKeeperResult result) {
        if (!EMClient.getInstance().isConnected()) {
            showMessage("未连接到聊天服务器");
        } else {
            // start chat acitivity
            // UserCacheManager.save(String.valueOf(currentUser.getId()), currentUser.getNickName(), currentUser.getHeadImg());
            Intent intent = new Intent(this, ChatActivity.class);
            // it's single chat
            intent.putExtra(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);
            intent.putExtra(EaseConstant.EXTRA_USER_ID, String.valueOf(result.getHxName()));
            intent.putExtra(EaseConstant.EXTRA_USER_NAME, "管家");
            startActivity(intent);
        }
    }

    private void payByWechat(String sign) {
        PayInfo payInfo = GsonUtils.fromJson(sign, PayInfo.class);
        final IWXAPI msgApi = WXAPIFactory.createWXAPI(this, null);
        msgApi.registerApp(Constant.WX_APP_ID);
        if (!msgApi.isWXAppInstalled()) {
            showMessage(getString(R.string.please_install_wechat));
            return;
        }
        msgApi.sendReq(payInfo.getPayReq());
    }

    private void payByAlipay(String sign) {
        AlipayResult payObj = GsonUtils.fromJson(sign, AlipayResult.class);
        subscribe(Observable.create((ObservableOnSubscribe<PayResult>) emitter -> {
            PayTask payTask = new PayTask(this);
            Map<String, String> map = payTask.payV2(payObj.getSign(), true);
            emitter.onNext(new PayResult(map));
        }).subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(payResult -> {
                    if ("9000".equals(payResult.getResultStatus())) {
                        //EventBus.getDefault().post(new PayEvent(true, 0, "支付成功"));
                        // showMessage("支付成功");
                        onPaySuccess();
                    } else if ("6001".equals(payResult.getResultStatus())) {
                        //cancelOrder(new PayFeeCancelRequest(result.getTradeNo()));
                        showMessage("支付取消");
                    } else {
                        //EventBus.getDefault().post(new PayEvent(false, 0, "支付失败"));
                        showMessage("支付失败:" + payResult.getResultStatus());
                    }
                }));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onPayEvent(PayEvent payEvent) {
        if (payEvent.isSuccess()) {
            onPaySuccess();
        } else {
            showMessage(payEvent.getDesc());
        }
    }

    private void onPaySuccess() {
        ARouter.getInstance().build(ARouterUrlKt.OrderResultUrl)
                .withInt("type", OrderResultActivity.ORDER_PAY)
                .withInt("orderId", orderDetailResult.getId())
                .withString("orderNo", orderDetailResult.getOrderNum())
                .withString("appointmentTime", orderDetailResult.getAppointmentTime())
                .navigation();
    }

    /**
     * 根据订单状态显示订单信息
     *
     * @param result OrderDetailResult
     */
    private void displayOrder(OrderDetailResult result) {
        //tvStatus.setText(result.getStatusStr());
        tvAddress.setText(result.getAddress());
        tvAddressName.setText(result.getUserName());
        tvAddressPhone.setText(result.getUserPhone());
        tvAppointmentTime.setText(result.getAppointmentTime());


        tvServiceManager.setOnClickListener(v -> {
            showMessageOKCancel(this, "联系管家", v1 -> {
                // mPresenter.getKeeper();
                if (getApp().getUserInfo().getHkeeperId() > 0) {
                    if (!StringUtils.isEmpty(getApp().getUserInfo().getKeeperHxName())) {
                        ChatActivity.startKeeperChat(this, getApp().getUserInfo().getKeeperHxName());
                    } else {
                        showMessage("管家信息获取失败!");
                    }
                } else {
                    ARouter.getInstance().build(ARouterUrlKt.MineKeeperContainerUrl).navigation();
                }
            });
        });

        tvServiceParamsName.setText(result.getServiceParameterName());
        tvServiceParamsPrice.setText(String.format("¥%s", result.getFormatPrice(result.getUnitPrice())));
        tvServiceCount.setText(String.valueOf(result.getNum()));
        tvServiceParamsPrice.setText(String.format("¥%s", result.getUnitPriceStr()));
        tvFeeTotal.setText(FormatUtils.formatYuan(result.getOrderPrice()));
        tvFeeDiscount.setText(String.format("-¥%s", result.getCouponPriceStr()));
        tvPayFeeTotal.setText(String.format("¥%s", result.getActualPriceStr()));

        tvOrderNo.setText(String.format("订单编号:    %s", result.getOrderNum()));
        tvOrderTime.setText(String.format("下单时间:    %s", result.getCreateTime()));
        if (StringUtils.isEmpty(result.getPaymentTime())) {
            tvOrderPayTime.setVisibility(View.GONE);
            tvOrderPayWay.setVisibility(View.GONE);
        } else {
            tvOrderPayTime.setVisibility(View.VISIBLE);
            tvOrderPayTime.setText(String.format("支付时间:    %s", result.getPaymentTime()));
            tvOrderPayWay.setVisibility(View.VISIBLE);
            tvOrderPayWay.setText(String.format("支付方式:    %s", result.getPayTypeStr()));
        }

        if (StringUtils.isEmpty(result.getRemarks())) {
            tvOrderRemark.setVisibility(View.GONE);
        } else {
            tvOrderRemark.setVisibility(View.VISIBLE);
            tvOrderRemark.setText(String.format("备  注:    %s", result.getRemarks()));
        }

        showBottomButton(result);

    }

    private void showBottomButton(OrderDetailResult result) {
        if (result.getRefundStatus() != 0) {//退款流程
            if (result.getRefundStatus() == 3) {//退款已拒绝
                ivStatus.setImageResource(R.mipmap.icon_order_refund_failed);
                tvStatus.setText("退款失败");
                tvEventTimeFlag.setText("审核时间");
                btn01.setVisibility(View.GONE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn03.setText("重新申请");
                btn03.setOnClickListener(v -> {
                    if (result.getStatus() == 1 || result.getStatus() == 2) {
                        refund(0);
                    } else if (result.getStatus() >= 3) {
                        refund(1);
                    }
                });
            } else if (result.getRefundStatus() == 1) {
                ivStatus.setImageResource(R.mipmap.icon_order_refund_verify);
                tvStatus.setText("审核中");
                tvEventTimeFlag.setText("申请时间");
                btn01.setVisibility(View.GONE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn03.setText("取消退款");
                btn03.setOnClickListener(v -> cancelRefund());
            } else {
                tvRefundsMsg.setVisibility(View.VISIBLE);
                ivStatus.setImageResource(R.mipmap.icon_order_refund_success);
                tvStatus.setText("已退款");
                tvEventTimeFlag.setText("退款时间");
                btn01.setVisibility(View.VISIBLE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn01.setText("再次购买");
                btn03.setText("删除订单");
                btn01.setOnClickListener(v -> orderAgain());
                btn03.setOnClickListener(v -> deleteOrder());
            }
            tvEventTime.setText(result.getUpdateTime());
        } else {
            if (result.getStatus() == 0) {//代支付
                ivStatus.setImageResource(R.mipmap.icon_order_wait_pay);
                tvStatus.setText("订单待支付");
                tvEventTimeFlag.setText("剩余时间");
                btn01.setVisibility(View.VISIBLE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn01.setText("立即支付");
                btn03.setText("取消订单");
                btn01.setOnClickListener(v -> orderPay());
                btn03.setOnClickListener(v -> cancelOrder());
                viewActionMore.setVisibility(View.GONE);
                viewActionMore.setOnClickListener(v -> showDeletePopup());

                long timeSpan = TimeUtils.getTimeSpan(new Date(),
                        TimeUtils.string2Date(result.getCreateTime()), TimeConstants.SEC);

                int amountTime = (int) (15 * 60 - timeSpan);

                if (amountTime < 0) {
                    tvEventTimeFlag.setText("订单已失效");
                    tvEventTime.setVisibility(View.GONE);
                    btn01.setVisibility(View.VISIBLE);
                    btn01.setText("再次购买");
                    btn01.setOnClickListener(v -> orderAgain());
                    btn02.setVisibility(View.GONE);
                    btn03.setVisibility(View.GONE);
                    orderDetailResult.setInvalid();//设置订单状态为已取消
                    displayOrder(orderDetailResult);
                } else {
                    subscribe(Observable.interval(0, 1, TimeUnit.SECONDS)
                            .take(amountTime)
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(aLong -> {
                                if (amountTime - aLong <= 1) {
                                    tvEventTime.setVisibility(View.GONE);
                                    tvEventTimeFlag.setText("订单已失效");
                                    orderDetailResult.setInvalid();//设置订单状态为已取消
                                    displayOrder(orderDetailResult);
                                    EventBus.getDefault().post(new OrderEvent(OrderEvent.INVALID, orderId));
                                } else {
                                    if (tvEventTime != null) {
                                        int min = (int) ((amountTime - aLong) / 60);
                                        int sec = (int) (amountTime - aLong - min * 60);
                                        tvEventTime.setText(String.format("%s分%s秒", min, sec));
                                    }
                                }
                            }));
                }


            } else if (result.getStatus() == 1) {
                ivStatus.setImageResource(R.mipmap.icon_order_wait_work);
                tvStatus.setText("待服务");
                tvEventTimeFlag.setText("预计上门时间");
                tvEventTime.setText(result.getAppointmentTime());
                btn01.setVisibility(View.GONE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn03.setText("申请退款");
                btn03.setOnClickListener(v -> refund(0));
            } else if (result.getStatus() == 2) {
                ivStatus.setImageResource(R.mipmap.icon_order_wait_work);
                tvStatus.setText("待服务");
                tvEventTimeFlag.setText("预计上门时间");
                tvEventTime.setText(result.getAppointmentTime());
                btn01.setVisibility(View.GONE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn03.setText("申请退款");
                btn03.setOnClickListener(v -> refund(0));
            } else if (result.getStatus() == 3) {
                ivStatus.setImageResource(R.mipmap.icon_order_working);
                tvStatus.setText("服务中");
                tvEventTimeFlag.setText("正在为您服务");
                tvEventTime.setVisibility(View.GONE);
                btn01.setVisibility(View.GONE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn03.setText("投诉退款");
                btn03.setOnClickListener(v -> refund(1));
            } else if (result.getStatus() == 4) {//待评价
                ivStatus.setImageResource(R.mipmap.icon_order_finished);
                tvStatus.setText("已完成");
                tvEventTimeFlag.setText("感谢您的支持，欢迎再次光临");
                tvEventTime.setVisibility(View.GONE);
                btn01.setVisibility(View.VISIBLE);
                btn02.setVisibility(View.VISIBLE);
                btn03.setVisibility(View.VISIBLE);
                btn01.setText("再次购买");
                btn02.setText("评价晒单");
                btn03.setText("投诉退款");
                btn01.setOnClickListener(v -> orderAgain());
                btn02.setOnClickListener(v -> commentOrder());
                btn03.setOnClickListener(v -> refund(1));
                viewActionMore.setVisibility(View.VISIBLE);
                viewActionMore.setOnClickListener(v -> showDeletePopup());
            } else if (result.getStatus() == 5) {//已评价
                ivStatus.setImageResource(R.mipmap.icon_order_finished);
                tvStatus.setText("已完成");
                tvEventTimeFlag.setText("感谢您的支持，欢迎再次光临");
                tvEventTime.setVisibility(View.GONE);
                btn01.setVisibility(View.VISIBLE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn01.setText("再次购买");
                btn03.setText("投诉退款");
                btn01.setOnClickListener(v -> orderAgain());
                btn03.setOnClickListener(v -> refund(1));
                viewActionMore.setVisibility(View.VISIBLE);
                viewActionMore.setOnClickListener(v -> showDeletePopup());
            } else if (result.getStatus() == 6) {
                ivStatus.setImageResource(R.mipmap.icon_order_cancel);
                tvStatus.setText("订单已取消");
                tvEventTimeFlag.setText("取消时间");
                tvEventTime.setText(StringUtils.isEmpty(result.getUpdateTime()) ? TimeUtils.getNowString() : result.getUpdateTime());
                btn01.setVisibility(View.VISIBLE);
                btn02.setVisibility(View.GONE);
                btn03.setVisibility(View.VISIBLE);
                btn01.setText("再次购买");
                btn03.setText("删除订单");
                btn01.setOnClickListener(v -> orderAgain());
                btn03.setOnClickListener(v -> deleteOrder());
            }
        }
    }

    private void orderAgain() {
        ServiceResult.ServiceInfo params = new ServiceResult.ServiceInfo();
        params.setId(orderDetailResult.getServiceParameterId());
        params.setParameterName(orderDetailResult.getServiceParameterName());
        params.setCharges(orderDetailResult.getUnitPrice());
        ARouter.getInstance().build(ARouterUrlKt.OrderCreateUrl)
                .withSerializable("params", params)
                .navigation();
    }

    private void cancelOrder() {
        showMessageOKCancel(this, "是否确定取消订单", v -> {
            mPresenter.cancelOrder(orderId);
        });
    }

    private void deleteOrder() {
        showMessageOKCancel(this, "是否确定删除订单", v -> {
            // EventBus.getDefault().post(new OrderEvent(OrderEvent.DELETE, orderId));
            // new Handler().postDelayed(this::onBackPressedSupport, 1500);
            mPresenter.deleteOrder(orderId);
        });
    }

    private void cancelRefund() {
        showMessageOKCancel(this, "是否确定取消退款", v -> {
            mPresenter.cancelRefund(orderId);
        });

    }

    //退款类型（0:服务未发生申请退款 1:投诉退款 ）
    private void refund(int type) {
        ARouter.getInstance().build(ARouterUrlKt.OrderRefundUrl)
                .withSerializable("order", orderDetailResult)
                .withInt("refundType", type)
                .navigation(this, REQUEST_REFUND);
    }

    private void orderPay() {
        new QMUIBottomSheet.BottomListSheetBuilder(this)
                .addItem(R.mipmap.ic_pay_wechat, "微信", "微信")
                .addItem(R.mipmap.ic_pay_alipay, "支付宝", "支付宝")
                .setGravityCenter(true)
                .setOnSheetItemClickListener((dialog, itemView, position1, tag) -> {
                    dialog.dismiss();
                    OrderPayParams payParams = new OrderPayParams();
                    payParams.setOrderId(orderDetailResult.getId());
                    payParams.setOrderNum(orderDetailResult.getOrderNum());
                    payWay = position1 == 0 ? 2 : 1;
                    payParams.setPayType(payWay);
                    mPresenter.payOrder(payParams);
                    showLoading("正在请求...");
                })
                .build().show();
    }

    private void commentOrder() {
        ARouter.getInstance().build(ARouterUrlKt.OrderEvaluateEditUrl)
                .withInt("orderId", orderId)
                .withString("avatarUrl", orderDetailResult.getThumbnail())
                .withString("serviceName", orderDetailResult.getServiceParameterName())
                .withString("servicePrice", orderDetailResult.getUnitPriceStr())
                .navigation(this, REQUEST_EVALUATE);
    }

    @SuppressWarnings("unchecked")
    private void showDeletePopup() {
        if (deletePopup == null) {
            String[] items = new String[]{"删除订单"};
            List<String> data = new ArrayList<>();
            Collections.addAll(data, items);
            ArrayAdapter adapter = new ArrayAdapter(this, R.layout.item_simple_list_center, data);
            deletePopup = QMUIPopups.listPopup(this, SizeUtils.dp2px(120),
                    SizeUtils.dp2px(54), adapter, (parent, view, position, id) -> {
                        deleteOrder();
                        deletePopup.dismiss();
                    });
        }
        deletePopup.show(viewActionMore);
    }

    @Override
    public void onTaskSuccess(int taskId) {
        super.onTaskSuccess(taskId);
        if (taskId == OrderPresenter.CANCEL) {
            showLoading("正在更新");
            EventBus.getDefault().post(new OrderEvent(OrderEvent.UPDATE, orderId));
            loadData();
        } else if (taskId == OrderPresenter.DELETE) {
            showMessage("订单已删除");
            EventBus.getDefault().post(new OrderEvent(OrderEvent.DELETE, orderId));
            new Handler().postDelayed(this::onBackPressedSupport, 1500);
        } else if (taskId == OrderPresenter.CANCEL_REFUND) {
            showLoading("正在更新");
            EventBus.getDefault().post(new OrderEvent(OrderEvent.UPDATE, orderId));
            loadData();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_REFUND) {
            if (resultCode == RESULT_OK) {
                loadData();
            }
        } else if (requestCode == REQUEST_EVALUATE) {
            if (resultCode == RESULT_OK) {
                loadData();
                EventBus.getDefault().post(new OrderEvent(OrderEvent.UPDATE, orderId));
            }
        }
    }
}
